//
//  HLIMKitMessageImageContentView.m
//  YueYue
//
//  Created by hulu001 on 2024/1/12.
//

#import "HLIMKitMessageImageContentView.h"

@interface HLIMKitMessageImageContentView ()

@property (nonatomic, strong) CAShapeLayer *maskLayer;

@end

@implementation HLIMKitMessageImageContentView


- (instancetype)init
{
    self = [super init];
    
    if (self) {
        self.opaque = YES;
        _imageView  = [[UIImageView alloc] initWithFrame:CGRectZero];
        _imageView.contentMode = UIViewContentModeScaleAspectFill;
        _imageView.clipsToBounds = YES;
        _imageView.image = [UIImage imageNamed:@"imImagePlaceholder"];
        _imageView.layer.cornerRadius = 8;
        [self addSubview:_imageView];
    }
    
    return self;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    self.imageView.frame = self.bounds;
    
//    self.imageView.layer.mask = self.maskLayer;
}

- (void)refreshData:(HLIMKitMessageModel *)messageModel
{
    [super refreshData:messageModel];
    
    NIMImageObject *imageObject = (NIMImageObject *)messageModel.message.messageObject;
    [self.imageView sd_setImageWithURL:[NSURL URLWithString:imageObject.url] placeholderImage:[UIImage imageNamed:@"imImagePlaceholder"]];
//    if ([imageObject.url containsString:@"gif"]){
//        [self.imageView sd_setImageWithURL:[NSURL URLWithString:imageObject.url] placeholderImage:[UIImage imageNamed:@"imImagePlaceholder"]];
//    } else {
//        [self.imageView sd_setImageWithURL:[NSURL URLWithString:imageObject.thumbUrl] placeholderImage:[UIImage imageNamed:@"imImagePlaceholder"]];
//    }
    
    
    
    // 计算裁剪圆角
    
//    CGFloat tableViewWidth = self.superview.width;
//
//    CGSize contentSize = [messageModel contentSize:tableViewWidth];
//
//    UIBezierPath *maskPath = NULL;
//
//    if (messageModel.message.isOutgoingMsg)
//    {
//        maskPath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, contentSize.width, contentSize.height) byRoundingCorners:UIRectCornerTopLeft | UIRectCornerBottomLeft | UIRectCornerBottomRight cornerRadii:CGSizeMake(14,14)];
//    }
//    else
//    {
//        maskPath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, contentSize.width, contentSize.height) byRoundingCorners:UIRectCornerTopRight | UIRectCornerBottomLeft | UIRectCornerBottomRight cornerRadii:CGSizeMake(14,14)];
//    }
//
//    //创建 layer
//    CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
//    maskLayer.frame = CGRectMake(0, 0, contentSize.width, contentSize.height);
//    //赋值
//    maskLayer.path = maskPath.CGPath;
//    self.maskLayer = maskLayer;
}

@end
